<template>
    <div>
        <ul class="mui-table-view">
            <li class="mui-table-view-cell mui-media" v-for="(item,index) in newslist" :key="index">
                <router-link :to="'/home/newsinfo/'+index">
                    <img class="mui-media-object mui-pull-left" :src="item.src">
                    <div class="mui-media-body">
                        <h4>{{item.title}}</h4>
                        <p class='mui-ellipsis'>
                            <span>{{item.time}}</span>
                            <span>点击：{{item.click}}次</span>
                        </p>
                    </div>
                </router-link>
            </li>
        </ul>
    </div>
</template>

<script>
    import { Toast } from 'mint-ui'
    import axios from 'axios'

    export default {
        data(){
            return { newslist:[]}
        },
        created(){
            this.getNewslist();
        },
        methods:{
            getNewslist(){
                //vue-resource
                // this.$http.get('/api/data').then(res=>{
                //     if(res.body.newslist.length==0){
                //         Toast('获取新闻数据失败')
                //     }else{
                //         this.newslist=res.body.newslist;
                //         console.log(this.newslist);
                //     }
                // })
                //axios
                axios.get('/api/data').then(res=>{
                    if(res.data.newslist.length==0){
                        Toast('获取新闻数据失败')
                    }else{
                        this.newslist=res.data.newslist;
                        console.log(this.newslist);
                    }
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
.mui-table-view{

    li{
        h4{
            font-size: 14px;
        }
        .mui-ellipsis{
            font-size: 12px;
            color:blue;
            display: flex;
            justify-content: space-between;
        }
    }
}
</style>